package com.ruoyi.system.service.impl;

import java.util.List;

import com.ruoyi.common.annotation.DataScope;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.token.TokenService;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.TLogisticsOrderInfoMapper;
import com.ruoyi.system.domain.TLogisticsOrderInfo;
import com.ruoyi.system.service.ITLogisticsOrderInfoService;

/**
 * 物流订单信息Service业务层处理
 * 
 * @author ruoyi
 * @date 2025-03-09
 */
@Service
public class TLogisticsOrderInfoServiceImpl implements ITLogisticsOrderInfoService 
{
    @Autowired
    private TLogisticsOrderInfoMapper tLogisticsOrderInfoMapper;

    /**
     * 查询物流订单信息
     * 
     * @param id 物流订单信息主键
     * @return 物流订单信息
     */
    @Override
    public TLogisticsOrderInfo selectTLogisticsOrderInfoById(Long id)
    {
        return tLogisticsOrderInfoMapper.selectTLogisticsOrderInfoById(id);
    }

    /**
     * 查询物流订单信息列表
     * 
     * @param tLogisticsOrderInfo 物流订单信息
     * @return 物流订单信息
     */
    @Override
    @DataScope(deptAlias = "d", userAlias = "u")
    public List<TLogisticsOrderInfo> selectTLogisticsOrderInfoList(TLogisticsOrderInfo tLogisticsOrderInfo)
    {
        LoginUser loginUser = SecurityUtils.getLoginUser();
        SysUser us = loginUser.getUser();
        if(us == null){
            throw new ServiceException("当前用户数据不能为空！");
        }
        //如果是客户，需要查看所有的客户代号下面的数据
        if("01".equals(us.getUserType())){
            tLogisticsOrderInfo.setCustomerCode(us.getUserName());
        }
        return tLogisticsOrderInfoMapper.selectTLogisticsOrderInfoList(tLogisticsOrderInfo);
    }

    /**
     * 新增物流订单信息
     * 
     * @param tLogisticsOrderInfo 物流订单信息
     * @return 结果
     */
    @Override
    public int insertTLogisticsOrderInfo(TLogisticsOrderInfo tLogisticsOrderInfo)
    {
        tLogisticsOrderInfo.setCreateTime(DateUtils.getNowDate());
        return tLogisticsOrderInfoMapper.insertTLogisticsOrderInfo(tLogisticsOrderInfo);
    }

    /**
     * 修改物流订单信息
     * 
     * @param tLogisticsOrderInfo 物流订单信息
     * @return 结果
     */
    @Override
    public int updateTLogisticsOrderInfo(TLogisticsOrderInfo tLogisticsOrderInfo)
    {
        tLogisticsOrderInfo.setUpdateTime(DateUtils.getNowDate());
        return tLogisticsOrderInfoMapper.updateTLogisticsOrderInfo(tLogisticsOrderInfo);
    }

    /**
     * 批量删除物流订单信息
     * 
     * @param ids 需要删除的物流订单信息主键
     * @return 结果
     */
    @Override
    public int deleteTLogisticsOrderInfoByIds(Long[] ids)
    {
        return tLogisticsOrderInfoMapper.deleteTLogisticsOrderInfoByIds(ids);
    }

    /**
     * 删除物流订单信息信息
     * 
     * @param id 物流订单信息主键
     * @return 结果
     */
    @Override
    public int deleteTLogisticsOrderInfoById(Long id)
    {
        return tLogisticsOrderInfoMapper.deleteTLogisticsOrderInfoById(id);
    }
}
